#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+1000;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Tree{
    LL l,r;long long maxval;
}tree[maxn*4];
LL pos[maxn],m=0;
long long dp[maxn];
struct P{
    LL a,b,h;
}o[maxn];
bool cmp(P A,P B){
     if(A.b==B.b) return A.a>B.a;
     return A.b>B.b;
}
void push_up(LL p){
     tree[p].maxval=max(tree[p*2].maxval,tree[p*2+1].maxval);
}
void build(LL p,LL l,LL r){
     tree[p].l=l;tree[p].r=r;tree[p].maxval=0;
     if(tree[p].l==tree[p].r){return;}
     LL mid=(l+r)>>1;
     build(p*2,l,mid);build(p*2+1,mid+1,r);
     push_up(p);
}
void modify(LL p,LL l,LL r,long long d){
     if(tree[p].l==tree[p].r){
        tree[p].maxval=max(tree[p].maxval,d);
        return;
     }
     LL mid=(tree[p].l+tree[p].r)>>1;
     if(l<=mid) modify(p*2,l,r,d);
     if(r>mid) modify(p*2+1,l,r,d);
     push_up(p);
}
long long query(LL p,LL l,LL r){
     if(l<=tree[p].l&&r>=tree[p].r){
        return tree[p].maxval;
     }
     LL mid=(tree[p].l+tree[p].r)>>1;
     long long ans=0;
     if(l<=mid) ans=max(ans,query(p*2,l,r));
     if(r>mid) ans=max(ans,max(tree[p*2].maxval,query(p*2+1,l,r)));
     return ans;
}
int main(void){
    LL n;n=read();
    for(LL i=1;i<=n;i++){
        LL a,b,h;a=read();b=read();h=read();
        pos[++m]=a;pos[++m]=b;pos[++m]=h;
        o[i].a=a;o[i].b=b;o[i].h=h;
    }
    sort(pos+1,pos+1+m);
    m=unique(pos+1,pos+1+m)-pos-1;
    sort(o+1,o+1+n,cmp);
    build(1,1,m);
    long long ans=0;
    for(LL i=1;i<=n;i++){
        LL inr=lower_bound(pos+1,pos+1+m,o[i].a)-pos;
        LL otr=lower_bound(pos+1,pos+1+m,o[i].b)-pos;
        long long val=query(1,1,otr-1);
        dp[i]=max(dp[i],val+o[i].h);
        ans=max(ans,dp[i]);
        modify(1,inr,inr,dp[i]);
    }
    printf("%lld\n",ans);
   	return 0;
}
